home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / pcvmm.exe / EXAMPLE.C < prev    next >
C/C++ Source or Header  |  1990-03-16  |  3KB  |  141 lines

  1.  
  2. /* requires atleast MSC 5.0 */
  3.  
  4. #include <stdio.h>
  5. #include <conio.h>
  6.  
  7. #include "pcvmm.h"
  8.  
  9. #define MAXALLOCS   10000
  10.  
  11.  
  12. typedef struct num_list
  13. {
  14.     VHAND next;
  15.     char  number[20];
  16.     char  dummy_data[128];
  17. } NUM_LIST;
  18.  
  19.  
  20. void        main(void);
  21.  
  22. static void NearToFarCopy( void far *dst, void *src, unsigned short len );
  23. static void FarToNearCopy( void *dst, void far *src, unsigned short len );
  24.  
  25.  
  26. void main()
  27. {
  28.  
  29.     int             i;
  30.     VHAND           prev_vh,
  31.                     vh = VH_NULL;
  32.     NUM_LIST    far *nl;
  33.     char            number[20];
  34.  
  35.     puts("The pcVMM system will use your \"TMP\" environment variable\n"
  36.         "to determine where to create the virtual swap file. If \"TMP\"\n"
  37.         "is defined in your environment make sure at least 1.5MB is free\n"
  38.         "on the device associated with \"TMP\" for this example.\n"
  39.         "If you wish to abort hit ESC, otherwise any other key to\n"
  40.         "start the example program.");
  41.  
  42.     if (getch() == 27 )
  43.         exit(1);
  44.  
  45.  
  46.     if ((i = open_vmm( NULL )) )
  47.     {
  48.         printf("Error initializing pcVMM #%d.\n", i );
  49.         exit(1);
  50.     }
  51.  
  52.     printf("\nPerforming %d virtual memory allocations:\n", MAXALLOCS );
  53.  
  54.     for ( i = 0; i < MAXALLOCS; ++i )
  55.     {
  56.         prev_vh = vh;
  57.  
  58.         if ( (vh = vmm_alloc( sizeof(NUM_LIST) )) == VH_NULL )
  59.         {
  60.             printf("Error allocating pcVMM on allocation #%d.\n", i );
  61.             exit(1);
  62.         }
  63.  
  64.         if ( !(nl = vmm_deref( vh )) )
  65.         {
  66.             printf("Error vmm_deref() fail on block #%d\n", i );
  67.             exit(1);
  68.         }
  69.  
  70.         nl->next = prev_vh;
  71.  
  72.         (void) itoa( i, number, 10 );
  73.  
  74.         printf("\r%s", number );
  75.  
  76.         NearToFarCopy( nl->number, number, sizeof number );
  77.     }
  78.  
  79.     /* vh == virtual handle pointing to the head of the linked list */
  80.  
  81.     printf("\nReferencing %d virtual memory allocations:\n", MAXALLOCS );
  82.  
  83.  
  84.     for ( i = MAXALLOCS; i >= 0 ; --i )
  85.     {
  86.         if ( !(nl = vmm_deref( vh )) )
  87.         {
  88.             printf("Error vmm_deref() fail on block #%d\n", i );
  89.             exit(1);
  90.         }
  91.  
  92.         vh = nl->next;  // get next virtual handle
  93.  
  94.         FarToNearCopy( number, nl->number, sizeof nl->number );
  95.  
  96.         printf("\r%s", number );
  97.  
  98.     }
  99.  
  100.     putchar('\n');
  101.  
  102.     close_vmm();
  103.  
  104.     exit(0);
  105. }
  106.  
  107. static void NearToFarCopy( void far *dst, void *src, register unsigned short len )
  108. {
  109.     unsigned char far       *d = dst;
  110.     register unsigned char  *s = src;
  111.  
  112.     while (len--)
  113.         *d++ = *s++;
  114. }
  115.  
  116. static void FarToNearCopy( register void *dst, void far *src, register unsigned short len )
  117. {
  118.     register unsigned char  *d = dst;
  119.     unsigned char  far      *s = src;
  120.  
  121.     while (len--)
  122.         *d++ = *s++;
  123. }
  124.  
  125. /* EOF */
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.